Get Chat Labels

Get all labels assigned to a specific chat.

GET
https://api.wawp.net/v2/labels/chats/{chatId}?access_token=123456789&chatId=123456789%40c.us&instance_id=123456789

Authentication Required

Login to swap the placeholders with your real Instance ID and Access Token.

Log In
Test /v2/labels/chats/{chatId} endpoint
GET
GET

No query parameters required

This endpoint doesn't expect data in the URL.

Best practices

  • Use this to build 'Smart Views' in your custom CRM.

  • Fetch only the necessary fields to optimize performance.

Reading the Thread Metadata: Fetch All Labels for a Chat

Individual conversations often wear many hats. A single chat with a customer might simultaneously be a "VIP," have a "Pending Payment," and be "Assigned to Alice." The Get Chat Labels endpoint allows you to retrieve the full array of labels currently attached to a specific chat identifier.


🏗️ Core Concept

This endpoint is the primary tool for Conversational Discovery. It answers the question: "What is the current business context of this specific thread?"

Key Capabilities:

  1. UI Hydration: Populate the "tags" or "labels" section of your custom agent dashboard when a chat is selected.
  2. Conditional Logic: Trigger different bot responses or agent alerts based on the chat's existing labels.
  3. State Audit: Verify if a chat has correctly transitioned through your workflow stages (e.g., ensuring "Lead" was removed before "Customer" was added).

🚀 Priority Use Cases

1. Smart Auto-Replies

Adjust your bot's tone or logic based on the user's current categories.

const labels = await api.getLabelsForChat('123456789@c.us');
const isVIP = labels.some(l => l.name === 'VIP');

if (isVIP) {
  await api.sendText(chatId, "Hello VIP! We've prioritized your request for immediate agent review.");
} else {
  await api.sendText(chatId, "Thanks for your message. We'll get back to you soon!");
}

2. CRM "State Refresh"

When an agent opens a contact in your CRM, fetch the latest WhatsApp labels to ensure the external CRM state matches the reality of the WhatsApp thread.

3. Preventing Duplicate Tags

Before adding a label, check if it's already present to avoid redundant API calls (though the add-label operation is idempotent).


🔄 State Consistency & Synchronization

In a multi-agent environment, ensuring that every agent sees the same labels at the same time is critical for preventing duplicated work.

The "Stale Data" Challenge

If Agent A adds a "Processing" label while Agent B is looking at the same chat, Agent B's dashboard may still show "Unassigned."

  • The Check-Before-Action Rule: Before an agent clicks "Send Invoice," your backend should call this endpoint to verify the chat hasn't already been tagged with "Invoice Sent" by another automated process or agent.
  • Websocket Pushing: Listen to label.chat.added and label.chat.removed webhooks. When they arrive, use this endpoint to fetch the full current state and push it via Websockets to all active agent browsers.

🛡️ Audit Logging & Compliance

Labels are often used to trigger significant business events (e.g., tagging a chat "Refund Approved" to trigger a payment gateway).

Building an Audit Trail

WhatsApp does not natively store a history of who applied a label and when. We recommend:

  1. Intercepting API Calls: Every time your system calls PUT /v2/labels/{id}/chats/{chatId}, log the user ID of the agent who initiated it.
  2. Snapshotting States: Periodically use this Get Chat Labels endpoint to take a snapshot of high-value chats to track their journey through your funnel.

🛠️ Integration Patterns: Visual Feedback Systems

The "Label Badge" Hydration

  1. Fetch List: Call this endpoint for the active chat.
  2. Map Styles: Cross-reference the color index with your local CSS theme.
  3. Render: Display a horizontal list of badges in your sidebar.
async function renderChatMetadata(chatId) {
  const currentLabels = await api.getLabelsForChat(chatId);
  
  return currentLabels.map(label => ({
     text: label.name,
     bgcolor: label.colorHex,
     isUrgent: label.color === 0 // Red index
  }));
}

⚠️ Important Behaviors & Edge Cases

  • Multi-Label Support: WhatsApp supports multiple labels per chat. This endpoint always returns an array, which may be empty if no labels are applied.
  • Id/Name/Color Trio: Each label in the response includes its unique ID, name, current color index, and hex code.
  • Performance: This is a lightweight call. However, if building a high-volume dashboard, consider caching the results until a webhook is received.

🤖 Advanced Integration: Bot Interaction Patterns

When building an automated assistant, the labels attached to a chat act as a "Contextual Memory."

The "Label-Aware" Bot

Your bot can query this endpoint at the start of a session to determine the user's tier or status.

  1. Incoming Message: User says "Price check."
  2. Lookup: Bot calls this endpoint.
  3. Branching logic:
    • If label "Wholesale" (ID 5) exists → Give bulk pricing.
    • If label "Retail" (ID 2) exists → Give standard pricing.
    • If no labels exist → Ask the user for their customer type.
async function getBotResponse(chatId, message) {
  const meta = await api.getLabelsForChat(chatId);
  const isWholesale = meta.some(l => l.id === '5');
  
  if (message.includes('price')) {
    return isWholesale ? getBulkPriceList() : getStandardPriceList();
  }
}

🎯 Best Practices

  1. Don't Over-Poll: Use Webhooks to keep your local database in sync instead of calling this every time a message is received.
  2. Handle Empty States: Gracefully render your UI when the response is an empty array [].
  3. Cross-Reference with Global Directory: Use the results here alongside the Get All Labels list to provide a full "Label Picker" experience for agents.

Request Parameters

Configure the parameters required to interact with this endpoint. All query and body arguments are listed below with their details.

URL Parameters

Passed in the URL query string
string

Your unique WhatsApp Instance ID

Example:
string

Your API Access Token

Example:
string

The unique ID of the chat (e.g., 123456789@c.us)

Example:

Request Samples

Use these ready-to-go code snippets to integrate our API into your project quickly and efficiently. Choose your preferred language and library.

1const baseUrl = "https://api.wawp.net";
2const endpoint = "/v2/labels/chats/123456789@c.us";
3const params = new URLSearchParams({
4 "instance_id": "123456789",
5 "access_token": "123456789"
6}).toString();
7
8
9fetch(`${baseUrl}${endpoint}${params ? '?' + params : ''}`, {
10 method: "GET",
11 headers: { "Content-Type": "application/json" },
12
13})
14 .then(async (response) => {
15 if (response.ok) {
16 const data = await response.json();
17 console.log("Success:", data);
18 return data;
19 }
20
21 // Error Handling
22 if (response.status === 401) {
23 console.error("Error 401: Unauthorized - Invalid or Missing Access Token");
24 }
25 if (response.status === 400) {
26 console.error("Error 400: Bad Request - Invalid Parameter Format");
27 }
28 if (response.status === 500) {
29 console.error("Error 500: Internal Server Error - Unexpected Failure");
30 }
31
32 const errorText = await response.text();
33 console.error(`Error ${response.status}: ${errorText}`);
34 })
35 .catch((error) => console.error("Network Error:", error));
Interactive Samples
Ln 35, Col 1javascript

Expected Responses

Explore all possible responses and outcomes from the server. We have documented each status code with data examples to make success and error handling easier.

List of labels for the chat
application/json
object *

Example

{
"0": {
  "id": "1",
  "name": "New Customer",
  "color": 0,
  "colorHex": "#ff9485"
  }
}
Bad Request - Invalid Parameter Format
Unauthorized - Invalid or Missing Access Token
Internal Server Error - Unexpected Failure
Previous TopicUnlink Label from Chat
Next TopicSet Chat Labels

Command Palette

Search for a command to run...